package com.yahoo.labs.snow.util;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.io.FileLinesCollection;
import it.unimi.dsi.io.FileLinesCollection.FileLinesIterator;

import java.nio.charset.Charset;

/**
 * A mapping from numbers to strings that is read from disk.
 * 
 * @author chato
 *
 */
public class Id2Str {
	final Object2ObjectOpenHashMap<String,String> node2name;
	
	public Id2Str(String inputFile) {
		node2name = new Object2ObjectOpenHashMap<String,String>();
		
		FileLinesCollection flc = new FileLinesCollection(inputFile, Charset.forName("UTF-8").name(), false);
		FileLinesIterator it = flc.iterator();
		while( it.hasNext() ) {
			String[] tokens = (it.next()).toString().split("\t", 2);
			String node = tokens[0];
			String name = tokens[1];
			node2name.put(node, name);
		}
	}
	
	public String getNameByNode(String node) {
		return node2name.get(node);
	}
}
